<?php get_header(); 
$category = $wp_query->get_queried_object();
$cat_name = $category->name;
$catID = $category->term_id;
//$cat_url = get_term_link($category->slug, 'category');
//$top_parent_id = get_category_top_parent_id($catID);
?>
<div id="container">	
    
    <div class="wrapper">
    	<div class="grid24" style="margin-top:20px;">
        	<?php get_sidebar(); ?>
            <div class="grid18"><!-- main content -->
            	<div class="crumbs">
                	<?php qt_custom_breadcrumbs(0, 1); ?>
                </div> 
              <section class="grid18">
                	<h1><?php echo $cat_name; ?></h1>
                    <div class="white_frame">
                    <?php 
                    if( $catID == 1 ) {
                        echo category_description(1);
                        $mysql = $wpdb->get_results("SELECT *
                        FROM $wpdb->terms t
                        INNER JOIN $wpdb->term_taxonomy tt ON(t.term_id = tt.term_id)  
                        WHERE parent = ". $catID);
                        foreach ( $mysql as $cate ) { 
                            $tag_image	= get_option('_tag_image'. $cate->term_id);
                            //$cate->name; ?>
                            <article class="recommend">
                            <?php if( $tag_image ) { ?>
                                <figure class="featured-thumbnail">
                                     <a href="<?php echo get_category_link($cate->term_id); ?>">
                                        <img src="<?php echo $tag_image; ?>" alt="<?php echo $cate->name; ?>" />
                                     </a>                                   
                                </figure>
                            <?php 
                            } ?>
                                <div class="grid12">
                                    <h2><a href="<?php echo get_category_link($cate->term_id); ?>"><?php echo $cate->name; ?></a></h2>
                                    <?php //echo get_content_using_wp_editor($cate->description); 
                                    echo GetWords($cate->description, 300); ?>
                                </div>                    	
                            </article>
                            <?php
                        }
                    } else {
                        while ( have_posts() ) : the_post(); 
                        ?>
                        <article class="recommend">
                            <figure class="featured-thumbnail">
                                 <a href="<?php the_permalink(); ?>">
                                        <?php 
                                            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                                              the_post_thumbnail('thumbnail');
                                            } 
                                         ?>
                                 </a>                                   
                            </figure>
                            <div class="grid12">
                                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <p>
                                <?php 
                                    $thuoctinh_arr = get_post_meta( $post->ID, '_mb_attribute', true );
                                    echo $thuoctinh_arr["tomtat"];
                                    //echo GetWords($thuoctinh_arr["tomtat"], 350);
                                ?>
                                </p>                            
                            </div>                    	
                        </article>
                        <?php endwhile; 
                    } ?>
                    </div><!-- end white frame -->
            </section>
    
          </div><!-- content -->
            
        </div><!-- grid 24 -->
    </div><!-- wrapper -->
   
</div> <!-- container -->
<?php get_footer(); ?>